##################Combined - humanitarian#################

##############
##  Plot ##
##############

library(stringr)
library(dplyr)
library(ggplot2)
library(grid)
library(gtable) 
library(readr)

# Import Data
setwd("Replication_JOP")
ptacr <- read_delim("multinomial_results_r_hum_order.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)



# Create intervals
#clo <- ptacr$dif - 1.96*ptacr$se
#chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(  rep("Strong Peace",3),
                                            rep("Mild Peace",3),
                                            rep("Mild Violence",3),
											rep("Strong Violence",3)

              )
                      

ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Strong Peace",
                                      "Mild Peace",
                                      "Mild Violence",
                                      "Strong Violence"))

# Create new labels

  ptacr$labels <- c("1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  )

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ))
  
category_shortnames <- c(
      `Strong Peace` = "Strong Peace",
       `Mild Peace` = "Mild Peace",
   `Mild Violence` = "Mild Violence",
  `Strong Violence` = "Strong Violence"
)

 
##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$point,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = high, xmin = low, height = 0)) +
  theme_bw() +
  #geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=8, color = "black"),
        axis.text.y = element_text(size=7, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 7.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  #scale_x_continuous(labels = c("-2","-1","-0.5","0","0.5", "1", "1.5")) +
  scale_x_continuous(limits=c(0, 1)) +
  xlab("Predicted Probabilities - Humanitarian Aid")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Results_MM_Hum_new_order.pdf")


##################Combined - transitional#################

##############
##  Plot ##
##############

# Import Data
ptacr <- read_delim("multinomial_results_r_trans_order.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)



# Create intervals
#clo <- ptacr$dif - 1.96*ptacr$se
#chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(  rep("Strong Peace",3),
                                            rep("Mild Peace",3),
                                            rep("Mild Violence",3),
											rep("Strong Violence",3)

              )
                      

ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Strong Peace",
                                      "Mild Peace",
                                      "Mild Violence",
                                      "Strong Violence"))

# Create new labels

  ptacr$labels <- c("1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  )

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ))
  
category_shortnames <- c(
      `Strong Peace` = "Strong Peace",
       `Mild Peace` = "Mild Peace",
   `Mild Violence` = "Mild Violence",
  `Strong Violence` = "Strong Violence"
)


##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$point,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = high, xmin = low, height = 0)) +
  theme_bw() +
  #geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=8, color = "black"),
        axis.text.y = element_text(size=7, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 7.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  #scale_x_continuous(labels = c("-2","-1","-0.5","0","0.5", "1", "1.5")) +
  scale_x_continuous(limits=c(0, 1)) +
  xlab("Predicted Probabilities - Transitional Aid")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Results_MM_Trans_new_order.pdf")

##################Combined - development#################

##############
##  Plot ##
##############

# Import Data

ptacr <- read_delim("multinomial_results_r_dev_order.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)




# Create intervals
#clo <- ptacr$dif - 1.96*ptacr$se
#chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(  rep("Strong Peace",3),
                                            rep("Mild Peace",3),
                                            rep("Mild Violence",3),
											rep("Strong Violence",3)

              )
                      

ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Strong Peace",
                                      "Mild Peace",
                                      "Mild Violence",
                                      "Strong Violence"))

# Create new labels

  ptacr$labels <- c("1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  )

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ))
  
category_shortnames <- c(
      `Strong Peace` = "Strong Peace",
       `Mild Peace` = "Mild Peace",
   `Mild Violence` = "Mild Violence",
  `Strong Violence` = "Strong Violence"
)


##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$point,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = high, xmin = low, height = 0)) +
  theme_bw() +
  #geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=8, color = "black"),
        axis.text.y = element_text(size=7, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 7.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  #scale_x_continuous(labels = c("-2","-1","-0.5","0","0.5", "1", "1.5")) +
  scale_x_continuous(limits=c(0, 1)) +
  xlab("Predicted Probabilities - Development Aid")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Results_MM_Dev_new_order.pdf")


##################Combined - budgetary#################

##############
##  Plot ##
##############

# Import Data
ptacr <- read_delim("multinomial_results_r_bud_order.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)



# Create intervals
#clo <- ptacr$dif - 1.96*ptacr$se
#chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(  rep("Strong Peace",3),
                                            rep("Mild Peace",3),
                                            rep("Mild Violence",3),
											rep("Strong Violence",3)

              )
                      

ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Strong Peace",
                                      "Mild Peace",
                                      "Mild Violence",
                                      "Strong Violence"))

# Create new labels

  ptacr$labels <- c("1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  )

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ,
                       "1: Decrease", "2: No Change", "3: Increase"  ))
  
category_shortnames <- c(
      `Strong Peace` = "Strong Peace",
       `Mild Peace` = "Mild Peace",
   `Mild Violence` = "Mild Violence",
  `Strong Violence` = "Strong Violence"
)

##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$point,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = high, xmin = low, height = 0)) +
  theme_bw() +
  #geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=8, color = "black"),
        axis.text.y = element_text(size=7, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 7.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  #scale_x_continuous(labels = c("-2","-1","-0.5","0","0.5", "1", "1.5")) +
  scale_x_continuous(limits=c(0, 1)) +
  xlab("Predicted Probabilities - Budgetary Aid")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Results_MM_Bud_new_order.pdf")

